//
// Created by xu on 2024/11/12.
//
#include <libavformat/avformat.h>
#include <libavformat/avio.h>

int show_metadata(const char *input_file) {
    // 设置日志级别
    av_log_set_level(AV_LOG_INFO);

    AVFormatContext *fmt_ctx = NULL;
    const AVDictionaryEntry *tag = NULL;
    int ret;

    if ((ret = avformat_open_input(&fmt_ctx, input_file, NULL, NULL))) {
        return ret;
    }

    if ((ret = avformat_find_stream_info(fmt_ctx, NULL)) < 0) {
        av_log(NULL, AV_LOG_ERROR, "Cannot find stream information\n");
        return ret;
    }

    while ((tag = av_dict_iterate(fmt_ctx->metadata, tag))) {
        printf("---> %s=%s\n", tag->key, tag->value);
    }

    printf("----> nb_streams=%d\n", fmt_ctx->nb_streams);

    avformat_close_input(&fmt_ctx);
    return 0;
}

int main(int argc, char *argv[]) {
    int ret;
    ret = show_metadata("C:\\Users\\xu\\Downloads\\123.mp4");
    return ret;
}